import './index.scss';
declare const layui: any;
declare const $: any;

layui.use(['layer', 'form'], function () {
  const layer = layui.layer,
    upload = layui.upload;
  upload.render({
    elem: '.upload-wraps',
    url: "https://zhaosheng.ieduchina.com/zsmanager/Api/uploadFile",
    field: "photo",
    done: function (res) {
      if (res.status == 1) {
        const img = document.createElement("img");
        img.src = "".concat(res.data);
        $(this.item).html(img);
        $(this.item).closest(".upload").find("input[type='hidden']").val(img.src);
      }
      else {
        layer.msg('上传失败');
      }
    },
    error: function (err) {
      console.log(err);
    }
  });

  $.each($(".upload"), function (_acc, item) {
    const value = $(item).find("input[type=hidden]") && $(item).find("input[type=hidden]").val();
    if (value) {
      const img = document.createElement("img");
      img.src = "".concat(value);
      $(item).parent().find(".upload-wraps").html(img);
    }
  })
})
